package com.jack.payment.service.basic.impl;

import com.jack.payment.constant.enums.TimeEnum;
import com.jack.payment.dao.home.HomeResultDao;
import com.jack.payment.entity.business.BasicColumnBo;
import com.jack.payment.entity.filter.CommonPaging;
import com.jack.payment.entity.filter.RestFilter;
import com.jack.payment.entity.result.HomeVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HomeServiceImpl {
    private Logger log = LoggerFactory.getLogger(HomeServiceImpl.class);

    @Autowired
    private HomeResultDao homeResultDao;

    /**
     * 获取首页支付数据
     * @return
     */
    public HomeVo getPayGmvDetail(CommonPaging filter) {
        HomeVo homeVo = new HomeVo();
        homeVo.setBillingRate(getBillingRateList(filter));
        homeVo.setRecentRate(getBillingDateTFilterList(filter, TimeEnum.DAY));
        return homeVo;
    }

    /**
     * 账单渠道数据展示
     * @param filter
     * @return
     */
    public List<BasicColumnBo> getBillingRateList(CommonPaging filter) {
        RestFilter.HomeFilter homeFilter = new RestFilter.HomeFilter();
        BeanUtils.copyProperties(filter, homeFilter);
        homeFilter.setFilterColumn("channel");
        homeFilter.setGroupColumn("channel");
        return homeResultDao.getPayGMVDetail(homeFilter);
    }

    /**
     * 账单渠道数据展示  各个时间
     * @param filter
     * @return
     */
    public List<BasicColumnBo> getBillingDateTFilterList(CommonPaging filter, TimeEnum timeEnum) {
        RestFilter.HomeFilter homeFilter = new RestFilter.HomeFilter();
        BeanUtils.copyProperties(filter, homeFilter);
        homeFilter.setFilterColumn(timeEnum.getTimeType() + "(FROM_UNIXTIME(end_time))");
        homeFilter.setGroupColumn(timeEnum.getTimeType() + "(FROM_UNIXTIME(end_time))");
        return homeResultDao.getPayGMVDetail(homeFilter);
    }

}
